//
//  NewsInfoBottomView.m
//  GuShiNews
//
//  Created by huachun on 2019/8/16.
//  Copyright © 2019 Jones. All rights reserved.
//

#import "NewsInfoBottomView.h"

@interface NewsInfoBottomView ()

@property (nonatomic, strong) NSMutableArray *Button_array;
@property (nonatomic, strong) UILabel        *Countlabel;

@end

@implementation NewsInfoBottomView

+ (NewsInfoBottomView *)show:(CGRect)frame{
    NewsInfoBottomView *view = [[NewsInfoBottomView alloc] initWithFrame:frame];
    return view;
}

- (instancetype)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        
        _Button_array = [NSMutableArray new];
        
        NSArray *image_list = [[NSArray alloc] initWithObjects:@"news_back",@"news_commont",@"news_like_no",@"news_more", nil];
        
        __block CGFloat l_w = RECRWITCH/image_list.count;
        
        [image_list enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(l_w * idx, 5, l_w, frame.size.height-10)];
            button.tag = idx;
            [button setImage:[UIImage imageNamed:obj] forState:UIControlStateNormal];
            button.imageView.contentMode = UIViewContentModeScaleAspectFit;
            [button addTarget:self action:@selector(touch_buttom:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:button];
            
            [self->_Button_array addObject:button];
        }];
        
        
        CALayer *topline = [CALayer new];
        topline.frame=CGRectMake(0, 0, RECRWITCH, 0.5);
        topline.backgroundColor = ColorMoren.CGColor;
        [self.layer addSublayer:topline];
        
        
        _Countlabel = [[UILabel alloc] initWithFrame:CGRectMake(l_w*1.5+9, -5, 20, 20)];
        _Countlabel.textColor = [UIColor whiteColor];
        _Countlabel.backgroundColor = [UIColor redColor];
        _Countlabel.layer.cornerRadius = 10;
        _Countlabel.layer.masksToBounds=YES;
        [self addSubview:_Countlabel];
        _Countlabel.hidden = YES;
        _Countlabel.textAlignment=NSTextAlignmentCenter;
        _Countlabel.font = [UIFont systemFontOfSize:11];
    }
    return self;
}

- (void)setlike:(BOOL)likeok{
    UIButton *linbutton = [_Button_array objectAtIndex:2];
    if (likeok) {
        [linbutton setImage:[UIImage imageNamed:@"news_like_yes"] forState:UIControlStateNormal];
    }else{
        [linbutton setImage:[UIImage imageNamed:@"news_like_no"] forState:UIControlStateNormal];
    }
}

- (void)setcommontcount:(NSString *)count{
    _Countlabel.hidden = NO;
    _Countlabel.text = count;
}

- (void)touch_buttom:(UIButton *)sender{
    _SelectBlock (sender.tag);
}

@end
